package com.smart.village.big.screen.controller.micro;

import com.smart.village.big.screen.domain.AjaxResult;
import com.smart.village.big.screen.service.MicroSmartMoHeManagerService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Parameters;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.ObjectUtils;
import org.springframework.web.bind.annotation.*;

import java.util.logging.Logger;

import static com.smart.village.big.screen.domain.AjaxResult.error;
import static com.smart.village.big.screen.domain.AjaxResult.success;

/**
 * 小程序-数智漠河-管理端
 */
@Tag(name = "小程序-数智漠河-管理端")
@RestController
@RequestMapping("/micro/smart/mohe/manager")
public class MicroSmartMoHeManagerController {
    Logger logger = Logger.getLogger(MicroSmartMoHeManagerController.class.getName());
    @Autowired
    private MicroSmartMoHeManagerService microSmartMoHeManagerService;

    /**
     * 帮办代办列表
     *
     * @return
     */
    @Operation(summary = "帮办代办列表")
    @GetMapping("getHelpList")
    @ResponseBody
    public AjaxResult getHelpList(
            @RequestParam(required = false) @Parameter(description = "镇id") String townNumber,
            @RequestParam(required = false) @Parameter(description = "村id") String villageNumber,
            @RequestParam(required = false) @Parameter(description = "开始时间") String beginDate,
            @RequestParam(required = false) @Parameter(description = "结束时间") String endDate,
            @RequestParam(required = false) @Parameter(description = "接受人身份证号") String iDCardNumber,
            @RequestParam(required = false) @Parameter(description = "状态  处理中  已完成 已评价") String status,
            @RequestParam(required = false, defaultValue = "1") @Parameter(description = "当前页数") int pageNum,
            @RequestParam(required = false, defaultValue = "10") @Parameter(description = "每页条数") int pageSize) {
        {

            try {
//                if (StringUtils.isBlank(townNumber)) {
//                    return error("镇id不能为空");
//                }
                if (ObjectUtils.isEmpty(pageNum) || pageNum == 0) {
                    pageNum = 1;
                }
                if (ObjectUtils.isEmpty(pageSize) || pageSize == 0) {
                    pageSize = 10;
                }
                return success(
                        microSmartMoHeManagerService.
                                getHelpList(townNumber, villageNumber, beginDate, endDate, iDCardNumber,status, pageNum, pageSize));
            } catch (Exception e) {
                e.printStackTrace();
                logger.severe(e.getMessage());
                return error("程序错误请联系系统管理员");
            }
        }
    }

    /**
     * 帮办代办-详情
     *
     * @return
     */
    @Operation(summary = "帮办代办-详情")
    @GetMapping("getHelpListDetail")
    @ResponseBody
    public AjaxResult getHelpListDetail(
            @RequestParam @Parameter(description = "申请编号") String applicationSerialNumber
    ) {
        try {
            return success(
                    microSmartMoHeManagerService.
                            getHelpListDetail(applicationSerialNumber));
        } catch (Exception e) {
            e.printStackTrace();
            logger.severe(e.getMessage());
            return error("程序错误请联系系统管理员");
        }

    }

    /**
     * 事件按照顶级分类进行查询 列表
     *
     * @return
     */
    @Operation(summary = "事件按照顶级分类进行查询 列表")
    @GetMapping("getLivelihoodDemandsList")
    @ResponseBody
    public AjaxResult getLivelihoodDemandsList(
            @RequestParam(required = false) @Parameter(description = "镇id") String townNumber,
            @RequestParam(required = false) @Parameter(description = "村id") String villageNumber,
            @RequestParam(required = false) @Parameter(description = "接受人身份证号") String iDCardNumber,
            @RequestParam(required = false) @Parameter(description = "开始时间") String beginDate,
            @RequestParam(required = false) @Parameter(description = "结束时间") String endDate,
            @RequestParam(required = false) @Parameter(description = "状态：  待办理、 已办结") String status,
            @RequestParam(required = false) @Parameter(description = "评价状态 ： 未评价 、 已评价") String ratingStatus,
            @RequestParam(required = false) @Parameter(description = "顶级事件分类") String parentCategorySerialNumber,
            @RequestParam(required = false, defaultValue = "1") @Parameter(description = "当前页数") int pageNum,
            @RequestParam(required = false, defaultValue = "10") @Parameter(description = "每页条数") int pageSize) {
        {

            try {
//                if (StringUtils.isBlank(townNumber)) {
//                    return error("镇id不能为空");
//                }

                if (ObjectUtils.isEmpty(pageNum) || pageNum == 0) {
                    pageNum = 1;
                }
                if (ObjectUtils.isEmpty(pageSize) || pageSize == 0) {
                    pageSize = 10;
                }
                return success(
                        microSmartMoHeManagerService.
                                getLivelihoodDemandsList(townNumber, villageNumber,iDCardNumber, beginDate, endDate, status,ratingStatus,parentCategorySerialNumber, pageNum, pageSize));
            } catch (Exception e) {
                e.printStackTrace();
                logger.severe(e.getMessage());
                return error("程序错误请联系系统管理员");
            }
        }
    }


    /**
     * 民生诉求-详情
     *
     * @return
     */
    @Operation(summary = "民生诉求-详情")
    @GetMapping("getLivelihoodDemandsDetail")
    @ResponseBody
    public AjaxResult getLivelihoodDemandsDetail(
            @RequestParam @Parameter(description = "诉求id") String complaintId
    ) {
        try {
            return success(
                    microSmartMoHeManagerService.
                            getLivelihoodDemandsDetail(complaintId));
        } catch (Exception e) {
            e.printStackTrace();
            logger.severe(e.getMessage());
            return error("程序错误请联系系统管理员");
        }

    }

    /**
     * 村民留言列表
     *
     * @return
     */
    @Operation(summary = "村民留言列表")
    @GetMapping("getVillagerComplainsList")
    @ResponseBody
    public AjaxResult getVillagerComplainsList(
            @RequestParam(required = false) @Parameter(description = "镇id") String townNumber,
            @RequestParam(required = false) @Parameter(description = "村id") String villageNumber,
            @RequestParam(required = false) @Parameter(description = "开始时间") String beginDate,
            @RequestParam(required = false) @Parameter(description = "结束时间") String endDate,
            @RequestParam(required = false) @Parameter(description = "状态 0 待办理 2 已办理") String replyStatus,
            @RequestParam(required = false, defaultValue = "1") @Parameter(description = "当前页数") int pageNum,
            @RequestParam(required = false, defaultValue = "10") @Parameter(description = "每页条数") int pageSize) {
        {

            try {
//                if (StringUtils.isBlank(townNumber)) {
//                    return error("镇id不能为空");
//                }
                if (ObjectUtils.isEmpty(pageNum) || pageNum == 0) {
                    pageNum = 1;
                }
                if (ObjectUtils.isEmpty(pageSize) || pageSize == 0) {
                    pageSize = 10;
                }
                return success(
                        microSmartMoHeManagerService.
                                getVillagerComplainsList(townNumber, villageNumber, beginDate, endDate, replyStatus, pageNum, pageSize));
            } catch (Exception e) {
                e.printStackTrace();
                logger.severe(e.getMessage());
                return error("程序错误请联系系统管理员");
            }
        }
    }

    /**
     * 村民留言-详情
     *
     * @return
     */
    @Operation(summary = "村民留言-详情")
    @GetMapping("getVillagerComplainsDetail")
    @ResponseBody
    public AjaxResult getVillagerComplainsDetail(
            @RequestParam @Parameter(description = "留言id") String complaintId
    ) {
        try {
            return success(
                    microSmartMoHeManagerService.
                            getVillagerComplainsDetail(complaintId));
        } catch (Exception e) {
            e.printStackTrace();
            logger.severe(e.getMessage());
            return error("程序错误请联系系统管理员");
        }

    }


    /**
     * 网格巡查任务列表
     *
     * @return
     */
    @Operation(summary = "网格巡查任务列表")
    @GetMapping("getPatrolCheckInList")
    @ResponseBody
    public AjaxResult getPatrolCheckInList(
            @RequestParam @Parameter(description = "身份证号") String iDCardNumber,
            @RequestParam(required = false) @Parameter(description = "开始时间") String beginDate,
            @RequestParam(required = false) @Parameter(description = "结束时间") String endDate,
            @RequestParam(required = false) @Parameter(description = "状态  未完成 、 已完成") String taskStatus,
            @RequestParam(required = false, defaultValue = "1") @Parameter(description = "当前页数") int pageNum,
            @RequestParam(required = false, defaultValue = "10") @Parameter(description = "每页条数") int pageSize) {
        {

            try {
                if (StringUtils.isBlank(iDCardNumber)) {
                    return error("身份证号不能为空");
                }
                if (ObjectUtils.isEmpty(pageNum) || pageNum == 0) {
                    pageNum = 1;
                }
                if (ObjectUtils.isEmpty(pageSize) || pageSize == 0) {
                    pageSize = 10;
                }
                return success(
                        microSmartMoHeManagerService.
                                getPatrolCheckInList(iDCardNumber, beginDate, endDate, taskStatus, pageNum, pageSize));
            } catch (Exception e) {
                e.printStackTrace();
                logger.severe(e.getMessage());
                return error("程序错误请联系系统管理员");
            }
        }
    }


    /**
     * 网格巡查任务-上报记录主表
     *
     * @return
     */
    @Operation(summary = "网格巡查任务-上报记录主表")
    @GetMapping("getPatrolResultMainGridList")
    @ResponseBody
    public AjaxResult getPatrolResultMainGridList(
            @RequestParam @Parameter(description = "主任务号") String taskPlanSerialNumber,
            @RequestParam(required = false, defaultValue = "1") @Parameter(description = "当前页数") int pageNum,
            @RequestParam(required = false, defaultValue = "10") @Parameter(description = "每页条数") int pageSize) {
        {

            try {
                if (StringUtils.isBlank(taskPlanSerialNumber)) {
                    return error("主任务号不能为空");
                }
                if (ObjectUtils.isEmpty(pageNum) || pageNum == 0) {
                    pageNum = 1;
                }
                if (ObjectUtils.isEmpty(pageSize) || pageSize == 0) {
                    pageSize = 10;
                }
                return success(
                        microSmartMoHeManagerService.
                                getPatrolResultMainGridList(taskPlanSerialNumber, pageNum, pageSize));
            } catch (Exception e) {
                e.printStackTrace();
                logger.severe(e.getMessage());
                return error("程序错误请联系系统管理员");
            }
        }
    }

    /**
     * 网格巡查任务-详情
     *
     * @return
     */
    @Operation(summary = "网格巡查任务-详情")
    @GetMapping("getPatrolCheckInDetail")
    @ResponseBody
    public AjaxResult getPatrolCheckInDetail(
            @RequestParam @Parameter(description = "任务编号") String taskPlanSerialNumber
    ) {
        try {
            return success(
                    microSmartMoHeManagerService.
                            getPatrolCheckInDetail(taskPlanSerialNumber));
        } catch (Exception e) {
            e.printStackTrace();
            logger.severe(e.getMessage());
            return error("程序错误请联系系统管理员");
        }

    }

    /**
     * 网格巡查任务-上报记录子表
     *
     * @return
     */
    @Operation(summary = "网格巡查任务-上报记录子表")
    @GetMapping("getPatrolResultDetailGridList")
    @ResponseBody
    public AjaxResult getPatrolResultDetailGridList(
            @RequestParam @Parameter(description = "任务编号") String resultMainSerialNumber
    ) {
        try {
            return success(
                    microSmartMoHeManagerService.
                            getPatrolResultDetailGridList(resultMainSerialNumber));
        } catch (Exception e) {
            e.printStackTrace();
            logger.severe(e.getMessage());
            return error("程序错误请联系系统管理员");
        }

    }

    /**
     * 巡边任务-根据身份证号查询我的巡边任务
     *
     * @return
     */
    @Operation(summary = "巡边任务-根据身份证号查询我的巡边任务")
    @GetMapping("getMyPatrolBorderList")
    @ResponseBody
    @Parameters({
            @Parameter(name = "iDCardNumber", description = "身份证号 必传"),
            @Parameter(name = "pageNum", description = "当前页数 非必传"),
            @Parameter(name = "pageSize", description = "每页条数 非必传"),
    })
    public AjaxResult getMyPatrolBorderList(
            @RequestParam @Parameter(description = "身份证号") String iDCardNumber,
            @RequestParam(required = false) @Parameter(description = "开始时间") String beginDate,
            @RequestParam(required = false) @Parameter(description = "结束时间") String endDate,
            @RequestParam(required = false) @Parameter(description = "状态  未开始 、 已完成") String status,
            @RequestParam(required = false, defaultValue = "1") @Parameter(description = "当前页数") int pageNum,
            @RequestParam(required = false, defaultValue = "10") @Parameter(description = "每页条数") int pageSize
    ) {
        try {
            return success(
                    microSmartMoHeManagerService.
                            getMyPatrolBorderList(iDCardNumber, beginDate, endDate,status, pageNum, pageSize));
        } catch (Exception e) {
            e.printStackTrace();
            logger.severe(e.getMessage());
            return error("程序错误请联系系统管理员");
        }

    }
    /**
     * 巡边任务-根据身份证号查询我的巡边任务
     *
     * @return
     */
    @Operation(summary = "巡边任务-根据身份证号查询我的巡边任务-不分页")
    @GetMapping("getMyPatrolBorderListNoPage")
    @ResponseBody
    @Parameters({
            @Parameter(name = "iDCardNumber", description = "身份证号 必传"),
    })
    public AjaxResult getMyPatrolBorderListNoPage(
            @RequestParam @Parameter(description = "身份证号") String iDCardNumber
    ) {
        try {
            return success(
                    microSmartMoHeManagerService.
                            getMyPatrolBorderListNoPage(iDCardNumber));
        } catch (Exception e) {
            e.printStackTrace();
            logger.severe(e.getMessage());
            return error("程序错误请联系系统管理员");
        }

    }

    /**
     * 巡边任务-根据身份证号和年月 查询日历信息
     *
     * @return
     */
    @Operation(summary = "巡边任务-根据身份证号和年月 查询日历信息")
    @GetMapping("getMyPatrolBorderCalendar")
    @ResponseBody
    @Parameters({
            @Parameter(name = "iDCardNumber", description = "身份证号 必传"),
            @Parameter(name = "year", description = "年 必传"),
            @Parameter(name = "month", description = "月 必传"),
    })
    public AjaxResult getMyPatrolBorderCalendar(
            @RequestParam @Parameter(description = "身份证号") String iDCardNumber,
            @RequestParam @Parameter(description = "年") String year,
            @RequestParam(required = false) @Parameter(description = "月") String month,
            @RequestParam(required = false) @Parameter(description = "开始时间 非必填") String beginDate,
            @RequestParam(required = false) @Parameter(description = "结束时间 非必填") String endDate
    ) {
        try {
            return success(
                    microSmartMoHeManagerService.
                            getMyPatrolBorderCalendar(iDCardNumber,year,month,beginDate,endDate));
        } catch (Exception e) {
            e.printStackTrace();
            logger.severe(e.getMessage());
            return error("程序错误请联系系统管理员");
        }

    }

    /**
     * 巡边任务详情-根据身份证号查询我的巡边任务
     *
     * @return
     */
    @Operation(summary = "巡边任务详情-根据子任务编号获取详情")
    @GetMapping("getMyPatrolBorderDetail")
    @ResponseBody
    @Parameters({
            @Parameter(name = "taskPlanSerialNumber", description = "子任务编号 必传")
    })
    public AjaxResult getMyPatrolBorderDetail(
            @RequestParam @Parameter(description = "子务任务编号") String taskPlanSerialNumber
    ) {
        try {
            return success(
                    microSmartMoHeManagerService.
                            getMyPatrolBorderDetail(taskPlanSerialNumber));
        } catch (Exception e) {
            e.printStackTrace();
            logger.severe(e.getMessage());
            return error("程序错误请联系系统管理员");
        }

    }


    /**
     * 工作台首页-待办事项
     *
     * @return
     */
    @Operation(summary = "工作台首页-待办事项")
    @GetMapping("getMyWillDoList")
    @ResponseBody
    public AjaxResult getMyWillDoList(
            @RequestParam @Parameter(description = "身份证号") String iDCardNumber,
            @RequestParam(required = false) @Parameter(description = "镇id") String townNumber,
            @RequestParam(required = false) @Parameter(description = "村id") String villageNumber,
            @RequestParam(required = false) @Parameter(description = "开始时间") String beginDate,
            @RequestParam(required = false) @Parameter(description = "结束时间") String endDate,
            @RequestParam(required = false) @Parameter(description = "状态  待办理 、 已办理") String status
) {
        {

            try {
                if (StringUtils.isBlank(iDCardNumber)) {
                    return error("身份证号不能为空");
                }
                return success(
                        microSmartMoHeManagerService.
                                getMyWillDoList(iDCardNumber,townNumber,villageNumber, beginDate, endDate, status));
            } catch (Exception e) {
                e.printStackTrace();
                logger.severe(e.getMessage());
                return error("程序错误请联系系统管理员");
            }
        }
    }


    @Operation(summary = "获取事件顶级分类列表")
    @GetMapping("getComplaintsCategoriesFirstLevel")
    @ResponseBody
    @Parameters({

    })
    public AjaxResult getComplaintsCategoriesFirstLevel(
            @RequestParam @Parameter(description = "身份证号") String iDCardNumber
    ) {
        try {
            return success(
                    microSmartMoHeManagerService.
                            getComplaintsCategoriesFirstLevel(iDCardNumber));
        } catch (Exception e) {
            e.printStackTrace();
            logger.severe(e.getMessage());
            return error("程序错误请联系系统管理员");
        }

    }

    /**
     * 人居环境-获取设备信息 根据身份证获取我所管辖的 村镇网格 下的 设备信息
     * @param iDCardNumber
     * @param townNumber
     * @param villageNumber
     * @return
     */
    @Operation(summary = "人居环境-获取设备信息 根据身份证获取我所管辖的 村镇网格 下的 设备信息")
    @Parameters(
            )
    @GetMapping("/getDeviceEnvironmentInformation")
    @ResponseBody
    public AjaxResult getPersonalInformation(
            @RequestParam @Parameter(description = "身份证号") String iDCardNumber,
            @RequestParam(required = false) @Parameter(description = "镇id") String townNumber,
            @RequestParam(required = false) @Parameter(description = "村id") String villageNumber

        ) {
        return AjaxResult.success(microSmartMoHeManagerService.getDeviceEnvironmentInformation(iDCardNumber,townNumber,villageNumber));
    }

    /**
     * 人居环境-垃圾清理 根据身份证获取我所管辖的 村镇网格 下的 垃圾桶异常数据
     * @param iDCardNumber
     * @param townNumber
     * @param villageNumber
     * @return
     */
    @Operation(summary = "人居环境-垃圾清理 根据身份证获取我所管辖的 村镇网格 下的 垃圾桶异常数据")
    @Parameters()
    @GetMapping("/getGarbageEnvironmentInformation")
    @ResponseBody
    public AjaxResult getGarbageEnvironmentInformation(
            @RequestParam @Parameter(description = "身份证号") String iDCardNumber,
            @RequestParam(required = false) @Parameter(description = "镇id") String townNumber,
            @RequestParam(required = false) @Parameter(description = "村id") String villageNumber,
            @RequestParam(required = false, defaultValue = "1") @Parameter(description = "当前页数") int pageNum,
            @RequestParam(required = false, defaultValue = "10") @Parameter(description = "每页条数") int pageSize

    ) {
        return AjaxResult.success(microSmartMoHeManagerService.getGarbageEnvironmentInformation(iDCardNumber,townNumber,villageNumber,pageNum,pageSize));
    }

    @Operation(summary = "人居环境-垃圾清理 详情")
    @Parameters()
    @GetMapping("/getGarbageEnvironmentInformationDetail")
    @ResponseBody
    public AjaxResult getGarbageEnvironmentInformationDetail(
            @RequestParam @Parameter(description = "编号") String equipmentTaskDetailSerialNumber

    ) {
        return AjaxResult.success(microSmartMoHeManagerService.getGarbageEnvironmentInformationDetail(equipmentTaskDetailSerialNumber));
    }

}
